Skip to content

Conversation

@Marenz
Copy link
Contributor

@Marenz Marenz commented Jun 18, 2025

This is only necessary because to cope with frequenz-floss/frequenz-repo-config-python#421. The check can raise an exception again once that it fixed.

Copilot AI review requested due to automatic review settings June 18, 2025 09:55
@Marenz Marenz requested a review from a team as a code owner June 18, 2025 09:55
@github-actions github-actions bot added part:docs Affects the documentation part:id Affects the id module labels Jun 18, 2025
@Marenz Marenz enabled auto-merge June 18, 2025 09:56
@Marenz Marenz requested review from llucax and removed request for florian-wagner-frequenz June 18, 2025 09:56

This comment was marked as outdated.

Copy link
Contributor

@llucax llucax left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the liberty of editing the PR description to give more context.

@Marenz Marenz requested a review from llucax June 18, 2025 11:22
Comment on lines 88 to 93
raise TypeError("BaseId cannot be instantiated directly. Use a subclass.")
# We want to raise an exception here, but currently can't due to
# https://github.com/frequenz-floss/frequenz-repo-config-python/issues/421
warn(
"BaseId cannot be instantiated directly. Use a subclass.", stacklevel=2
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait! This is the wrong exception! It should be this one!

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh lol. and I guess we have no test for this one 😆

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we don't 🤷

Not sure if it is worth adding now (pytest have some utils to test warnings are emitted).

Copy link
Contributor

@llucax llucax Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also add a test that BaseId raises if instantiated directly, this one should be easy too with with pytest.raises(TypeError, match="..."): BaseId(1))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

way ahead of you

@github-actions github-actions bot added the part:tests Affects the unit, integration and performance (benchmarks) tests label Jun 18, 2025
@Marenz Marenz requested review from Copilot and llucax June 18, 2025 11:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the behavior of duplicate prefix handling in BaseId to issue a warning rather than immediately raising an exception. Key changes include:

  • Adding tests for direct BaseId instantiation and non-unique prefix warning.
  • Updating BaseId to use warn() for duplicate prefix detection.
  • Adjusting release notes to reflect the change in behavior.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
tests/test_id.py Added tests to validate subclass instantiation and warning for duplicate prefixes.
src/frequenz/core/id.py Changed duplicate prefix handling from raising ValueError to using warn().
RELEASE_NOTES.md Updated the release notes to summarize the change in duplicate prefix behavior.
Comments suppressed due to low confidence (1)

src/frequenz/core/id.py:108

  • The docstring for init_subclass still indicates that a ValueError is raised for duplicate prefixes, but the code now issues a warning. Consider updating the docstring to reflect the current behavior.
        Raises:

warn(
f"Prefix '{str_prefix}' is already registered. "
"ID prefixes must be unique."
"ID prefixes must be unique.",
Copy link

Copilot AI Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to explicitly specify the warning category (e.g., UserWarning) in the warn() call for clarity and consistency, even though the default is UserWarning.

Suggested change
"ID prefixes must be unique.",
"ID prefixes must be unique.",
category=UserWarning,

Copilot uses AI. Check for mistakes.
@Marenz Marenz added this pull request to the merge queue Jun 18, 2025
Merged via the queue into frequenz-floss:v1.x.x with commit 130563d Jun 18, 2025
5 checks passed
@Marenz Marenz deleted the warn_not_raise branch June 18, 2025 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:id Affects the id module part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants